
import warnings
warnings.filterwarnings('ignore')
import pandas as pd

# 1、读取数据：从乳腺癌原始数据.xlsx文件中读取数据；检查基本信息。（3分）
df = pd.read_excel('乳腺癌原始数据.xlsx')
print(df.shape)
print(df.columns)
print(df.isnull().sum())
print(df.info())
# 2、删除包含任何缺失值的行（3分）
df.dropna(inplace=True)

# 3、提取数值特征，提取目标变量（3分）
y = df['严重度']
X = df.drop(['严重度'],axis=1)

# 4、划分训练集和测试集（3分）
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# 5、选择逻辑回归，决策树，GBDT三个模型进行建模。（3分）
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression(random_state=0,intercept_scaling=1,max_iter=100)

from sklearn.tree import DecisionTreeClassifier
clf2 = DecisionTreeClassifier(random_state=0,min_samples_split=2,min_samples_leaf=1,)

from sklearn.ensemble import GradientBoostingClassifier
clf3 = GradientBoostingClassifier(random_state=0,learning_rate=0.1,n_estimators=100,)

# 6、使用GridSearchCV进行超参数调优，要求最少优化模型至少三个参数（5分）
from sklearn.model_selection import GridSearchCV

clf6 = GridSearchCV(clf,{'random_state':[1,2,3],'intercept_scaling':[2,3,4],'max_iter':[5,6,7]},cv=5,scoring='accuracy')
lrw = clf6.fit(X_train,y_train)
print(clf6.best_estimator_)
print(clf6.best_score_)









# 7、选择合适的模型评估。（5分）




